using System;
using Network;
using pEventBus;
using UnityEngine;
using DG.Tweening;
using UnityEngine.UI;
using Google.Protobuf;
using System.Collections;
using com.shinian.fcg.fbs;
using FCG.cache.proxy_model;
using System.Collections.Generic;
using Com.Shinian.FcgProtocol.Pb;
using Google.Protobuf.Collections;
using Io.Marsdigital.CommonProtocol.Pb;
using CommonGoodsExchangeDTO = Io.Marsdigital.CommonProtocol.Pb.GoodsExchangeDTO;
using CommonGoodsExchangePackDTO = Io.Marsdigital.CommonProtocol.Pb.GoodsExchangePackDTO;
using GF.Debug;


//本地数据仓库
public class DataMgr : MonoSingleton<DataMgr> {
    public static bool SkillOnDeploy = true;
    public static FightResultDTO result;
    public static bool fromLogin = false;
    public RepeatedField<CommonGoodsExchangeDTO> DailyBonus = new RepeatedField<CommonGoodsExchangeDTO>();
    public static List<SkillEffectToPlayer> SkillPool = new List<SkillEffectToPlayer>();
    
    private void Awake()
    {
        NetMgr.Register(ProxyModelIndex.PlayerPM_dailyRewardTrigger, OnDailyReward);
    }

    //存储每日奖励数据
    void OnDailyReward(ProxyModelUpdateEvent p)
    {
        DailyBonus = ((CommonGoodsExchangePackDTO)p.attachData).Goods;
    }

    //清空每日奖励数据
    public void ClearDailyBonus()
    {
        DailyBonus.Clear();
    }

    //体力变化
    public int GetPhysical(int pos)
    {
        Dictionary<int, FightFootballerPosPM> myFormation = WebSocketManager.instance.FightScenePM().myFormation;
        Dictionary<int, FightFootballerPosPM> opponentFormation = WebSocketManager.instance.FightScenePM().opponentFormation;
        if (myFormation.ContainsKey(pos) && myFormation[pos].uid != 0) 
        {
            return WebSocketManager.instance.FightScenePM().footballers[myFormation[pos].uid].physical;
        }
        if (opponentFormation.ContainsKey(pos) && opponentFormation[pos].uid != 0) 
        {
            return WebSocketManager.instance.FightScenePM().footballers[opponentFormation[pos].uid].physical;
        }
        return 0;
    }

    //清除技能池
    public void ClearSkill()
    {
        Debug.Log("技能池清空");
        SkillPool.Clear();
    }

    //获取球员数据
    public static Footballer GetCardData(int rid)
    {
        if (rid == 100230082)
        {
            rid = 100430082;
        }
        if (!StaticDataUtil.instance.footballerCache.ContainsKey(rid))
        {
            Debugger.LogError("球员数据缺失" + rid);
            return new Footballer();
        }
        else
        {
            return StaticDataUtil.instance.footballerCache[rid];
        }
    }

    //获取金币
    public static int GetMoney()
    {
        return WebSocketManager.instance.PlayerPM().cash[StaticDataUtil.instance.baseEnumConfig.CashResourceTypeCash1].count;
    }

    //获取游戏币
    public static int GetCoin()
    {
        return WebSocketManager.instance.PlayerPM().cash[StaticDataUtil.instance.baseEnumConfig.CashResourceTypeCash2].count;
    }

    //获取球魂
    public static int GetSoul()
    {
        return WebSocketManager.instance.PlayerPM().cash[StaticDataUtil.instance.baseEnumConfig.CashResourceTypeSoul].count;
    }

    //获取技能数据
    public static Skill GetSkillData(int id)
    {
        if (!StaticDataUtil.instance.skillCache.ContainsKey(id))
        {
            Debugger.LogError("技能数据缺失" + id);
            return new Skill();
        }
        else
        {
            return StaticDataUtil.instance.skillCache[id];
        }
    }
}
